package weaver.interfaces.holyview.duss.action;

import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.holyview.duss.util.DataUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-23
 * @Description: 公告发布流程
 * @ModifyLog:
 **/
/*
 *@Description: 借款流程提交后调用付款单保存接口
 *@Param:
 *@return:
 *@Author: Dusongsong
 *@Date: 2020/12/10
 */
public class WeaPaymentAppliyAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        int userid = requestInfo.getRequestManager().getUserId();
        String method = "Save";
        baseBean.writeLog( "------WeaPaymentAppliyAction-------"+requestid );
        JSONObject jsonData = new JSONObject();
        try {
        String sql = "select t1.skdwmc,t1.fkrq,t1.scdjlx,t1.yfje,t1.zfzh \n" +
                "from "+tablename+" t left join "+tablename+"_dt1 t1\n" +
                "on t.id=t1.mainid where t.requestid = ?";
        rs.executeQuery( sql,requestid );
        while (rs.next()){
            String scdjlx = Util.null2String( rs.getString( "scdjlx" ) );
            jsonData.put("rq",Util.null2String(rs.getString( "fkrq" )));
            jsonData.put("jdrybm",getBm(Util.null2String(rs.getString( "skdwmc" ))));
            jsonData.put("je",Util.null2String(rs.getString( "yfje" )));
            jsonData.put("zfzh",DataUtil.getYhzhlb(Util.null2String(rs.getString( "zfzh" ))));
            baseBean.writeLog("jsonData=",jsonData.toJSONString());
            String result = "";
            if("0".equals(scdjlx)){
                result =  DataUtil.otherBusinessReceipt(jsonData);
            }
            if("1".equals(scdjlx)){
                result =  DataUtil.procurementBusinessReceipt(jsonData);
            }
            DataUtil.saveCallInterLog("付款单",method,result,requestid,userid);
            baseBean.writeLog("result="+result.toString());
        }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }

    public static String getBm(String skdwmc){
        RecordSet rs = new RecordSet(  );
        rs.executeQuery( "select A.bm from (\n" +
                "         select jdgysbm as bm,gysmc as mc,jdgysbm+gysmc as bmmc from uf_gysxxb\n" +
                "         union\n" +
                "         select bm,mc,bm+mc as bmmc from uf_qtwldw) A where A.bmmc='"+skdwmc+"'");
        rs.next();
        String bm = Util.null2String( rs.getString( "bm" ) );
        return bm;
    }

}
